import time
from functools import wraps


# 添加时间统计装饰器
def time_decorator(func_name):
    def decorator(func):
        def wrapper(*args, **kwargs):
            start_time = time.time()
            result = func(*args, **kwargs)
            end_time = time.time()
            print(f"{func_name} 执行时间: {end_time - start_time} 秒")
            return result
        return wrapper
    return decorator



def timethis(func):
    """
    函数执行时间装饰器
    用于统计函数执行时间的装饰器,使用方法:
    @timethis
    def func():
        pass
    
    Returns:
        装饰后的函数,会在执行完后打印函数名和执行时间
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        end = time.time()
        print(func.__name__, end-start)
        return result
    return wrapper